//
//  YuJiShouYiVC.m
//  BrushFace
//
//  Created by timer_q on 16/1/18.
//  Copyright © 2016年 Zzz. All rights reserved.
//

#import "YuJiShouYiVC.h"
#import "ARRequestModel.h"
#import "FinanceReqModel.h"
#import "HuanKuanHeaderView.h"
#import "HuanKuanFooterView.h"
#import "HuanKuanPlanCell.h"
#import "ARViewHepler.h"

@interface YuJiShouYiVC ()<UITableViewDataSource,UITableViewDelegate>
{
    UITableView *_tableView;
    NSMutableArray *_dataArray;
    HuanKuanHeaderView *huanKuanHeader;
    HuanKuanFooterView *huanKuanFooter;
#pragma mark-----yueyunpeng
    
    NSDictionary *_myShouyi;
}

@property (nonatomic,strong)FinanceReqModel *reqModel;
@end

@implementation YuJiShouYiVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self UIConfig];
    [self dataInit];
    
    
    
}
- (void)UIConfig{
    [self.navBar setTitle:@"预计收益"];
    [self.navBar setNavBackColor:[ARViewHepler getNavColor:1]];
    [self.navBar setLeftBtn:NAV_BAR_LEFT_BTN_TYPE_WHITE];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 74, SCREEN_WIDTH, SCREEN_HEIGHT-74) style:UITableViewStylePlain];
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.backgroundColor = UIColorFromRGB(ColorValueForBackView_Gray);
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    
    huanKuanHeader = [HuanKuanHeaderView loadBundleNib];
    huanKuanFooter = [HuanKuanFooterView loadBundleNib];
    huanKuanHeader.frame = CGRectMake(0, 0, SCREEN_WIDTH, 44);
    huanKuanFooter.frame = CGRectMake(0, 0, SCREEN_WIDTH, 100);
    _tableView.tableHeaderView = huanKuanHeader;
    _tableView.tableFooterView = huanKuanFooter;
    
}
- (void)dataInit{
    
    _dataArray = [[NSMutableArray alloc] init];
    
    _reqModel = [FinanceReqModel SceneModel];
    [_reqModel hope_genIncomeWithHopeId:self.hopeID andIsFace:self.isface andAmount:self.amount andConpousId:self.conpousId andCB:^(id output) {
        huanKuanFooter.Alabel.text = [NSString stringWithFormat:@"优惠：本金¥%@、利息¥%@",[NSString stringWithFormat:@"%@",@"0"],[NSString stringWithFormat:@"%@",[NSString stringWithFormat:@"%@",output[@"totalCouponsamountView"]]]];
        huanKuanFooter.BLabel.text = [NSString stringWithFormat:@"应还款总额：%@(含本金 ¥%@、利息¥%@)",[NSString stringWithFormat:@"%@",output[@"totalamount"]],[NSString stringWithFormat:@"%@",output[@"totalCapitalView"]],[NSString stringWithFormat:@"%@",output[@"totalInterestView"]]];
        [_dataArray removeAllObjects];
        [_dataArray addObjectsFromArray:[output objectForKey:@"data"]];
        
#pragma mark-----yueyunpeng
        
        _myShouyi = [[NSDictionary alloc] initWithDictionary:output];
        
        [_tableView reloadData];
    }];

}
#pragma mark - tableView Delegate and DataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _dataArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"HuanKuanPlanCell";
    HuanKuanPlanCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [HuanKuanPlanCell loadBundleNib];
    }
    NSDictionary *dict = [_dataArray objectAtIndex:indexPath.row];
    cell.dateLabel.text = [NSString stringWithFormat:@"%@",[dict objectForKey:@"plandate"]];
    cell.lixiLabel.text = [NSString stringWithFormat:@"%@",[dict objectForKey:@"interest"]];
    cell.benjinLabel.text = [NSString stringWithFormat:@"%@",[dict objectForKey:@"capital"]];

    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:NO];
}
#pragma mark - action

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
